const path = require('path')
const glob = require('glob')
const fs = require('fs')

const isDev = (process.env.NODE_ENV === 'development')
// const cdn = {
//     css: ['/static/css/vant.css', `/static/css/vendors.dll.css?${new Date().getTime()}`],
//     js: [`/static/js/vendors.dll.js?${new Date().getTime()}`]
// }

function getPages (globPath) {
    const pages = {}
    glob.sync(globPath).forEach((item) => {
        const stats = fs.statSync(item)
        if (stats.isDirectory()) {
            const basename = path.basename(item, path.extname(item))
            // 生成入口文件
            const entryFile = `src/views/${basename}/main.js`;
            fs.access(entryFile, (err) => {
                if (err) {
                    fs.appendFile(entryFile, entryData, function () { });
                }
            })

            pages[basename] = {
                entry: entryFile,
                  // 模板文件
            template: `public/index.html`,
            // 输出文件
            filename: 'index.html',
                // template: path.join(__dirname, '../entry/template.html'),
                // filename: isDev ? `${basename}.html` : `index.html`,
                // chunks: ['chunk-vendors', 'chunk-common', 'index'],
                // cdn: cdn
            }

        }
    })
    return pages
}

module.exports = getPages(path.join(__dirname, '../src/views/*'))
